#pragma once
#include "RBTree.h"
#include <iostream>

namespace lw
{
	template<class K, class V>
	struct KeyOfT
	{
		const K& operator()(const pair<K, V>& kv)
		{
			return kv.first;
		}
	};
	
	template<class K, class V, class Compare = less<K>>
	class Map
	{
	public:
		typedef typename RBTree<K, pair<K, V>, KeyOfT<K, V>, Compare>::iterator iterator;
		iterator begin()
		{
			return _tree.begin();
		}

		iterator end()
		{
			return _tree.end();
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret = Insert(make_pair(key, V()));
			return ret.first._node->_data.second;
		}

		pair<iterator, bool> Insert(const pair<K, V>& kv)
		{
			return _tree.Insert(kv);
		}
	private:
		RBTree<K, pair<K, V>, KeyOfT<K, V>, Compare> _tree;
	};
}